package l1j.opqlo.Server.L1World;

import java.util.Collection;
import java.util.Collections;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

import l1j.server.server.model.Instance.L1ItemInstance;


/**
 * 世界ITEM暫存區<BR>
 *
 * @author dexc
 *
 */
public class WorldItemEnchantTime {

	private static final Logger _log = Logger.getLogger(WorldItemEnchantTime.class.getName());

	private static WorldItemEnchantTime _instance;

	public static WorldItemEnchantTime get() {
		if (_instance == null) {
			_instance = new WorldItemEnchantTime();
		}
		return _instance;
	}

	private final ConcurrentHashMap<Integer, L1ItemInstance> _isItem;

	private Collection<L1ItemInstance> _allItemValues;

	private WorldItemEnchantTime() {
		this._isItem = new ConcurrentHashMap<Integer, L1ItemInstance>();
	}

	/**
	 * 全部ITEM
	 * @return
	 */
	public Collection<L1ItemInstance> all() {
		try {
			final Collection<L1ItemInstance> vs = this._allItemValues;
			return vs != null ? vs : (this._allItemValues = Collections.unmodifiableCollection(this._isItem.values()));
			//return Collections.unmodifiableCollection(_isCrown.values());

		} catch (final Exception e) {
			_log.log(Level.WARNING,e.getLocalizedMessage(), e);
		}
		return null;
	}

	/**
	 * 傳回ITEM數據
	 * @param clan_name
	 * @return
	 */
	public L1ItemInstance getItem(final Integer key) {
		return this._isItem.get(key);
	}

	/**
	 * ITEM清單
	 * @return
	 */
	public ConcurrentHashMap<Integer, L1ItemInstance> map() {
		return this._isItem;
	}

	/**
	 * 加入ITEM清單
	 * @param key
	 * @param value
	 */
	public void put(final Integer key, final L1ItemInstance value) {
		try {
			this._isItem.put(key, value);

		} catch (final Exception e) {
			_log.log(Level.WARNING,e.getLocalizedMessage(), e);
		}
	}

	/**
	 * 移出ITEM清單
	 * @param key
	 */
	public void remove(final Integer key) {
		try {
			this._isItem.remove(key);

		} catch (final Exception e) {
			_log.log(Level.WARNING,e.getLocalizedMessage(), e);
		}
	}
}
